package com.sixth.controller;

import com.sixth.entity.Goods;
import com.sixth.entity.Limit;
import com.sixth.service.GoodsService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.sixth.util.LayTab;
import com.sixth.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @program: project01
 * @description:
 * @author: 老魏
 * @create: 2021-12-18 15:06
 **/

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    //获取商品盘点信息
    @RequestMapping("getAllOutGoodsP")
    public LayTab getAllOutGoodsP(Goods goods, Limit limit, Integer bid){
        return goodsService.getAllOutGoodsP(goods,limit,bid);
    }
    //获取商品信息
    @RequestMapping("/getAllGoods")
    public LayTab getAllGoods(Goods goods, Limit limit){
        return goodsService.getAllGoods(goods, limit);
        }

    // 入库新增的全部查询
    @RequestMapping("/Goods")
    public LayTab getGoods(Goods goods, Limit limit){
        return  goodsService.getGoods(goods,limit);
    }
    //获取商品信息
    @RequestMapping("getAllOutGoods")
    public LayTab getAllOutGoods(Goods goods, Limit limit, Integer bid){
        return goodsService.getAllOutGoods(goods,limit,bid);
    }
    //修改和增加商品
    @RequestMapping("/addOrUpdateGoods")
   /* public CommonResult addOrUpdateGoods(Goods record)   {
        if (record.getGoodsid()!=null){
            return goodsService.update(record);
        }else {
            return goodsService.insert(record);
        }*/
    public CommonResult addOrUpdateGoods(Goods goods) throws IOException {
        System.out.println(goods);
        return this.goodsService.addOrUpdateGoods(goods);
    }
    //删除商品
    @RequestMapping("/delGoodsById")
    public CommonResult delete(Integer goodsid, Integer branchid){
        return goodsService.delete(goodsid,branchid);
    }
    //查看商品名字是否重复
    @RequestMapping({"getGoodsName"})
    public CommonResult getGoodsName(String goodsname) {
        CommonResult goods =goodsService.getGoodsName(goodsname);
        return goods;
    }
}
